﻿using CommunityToolkit.Mvvm.ComponentModel;
using CommunityToolkit.Mvvm.Input;
using System.Collections.ObjectModel;
using System.Windows;
using Wpf.Ui.Controls;

namespace MetaView.Shell.ViewModels;

public partial class MainWindowViewModel : ViewModel
{
    private readonly IModuleCatalog m_moduleCatalog;

    private bool _isInitialized = false;

    [ObservableProperty]
    private ObservableCollection<object> _navigationItems = [];
    // public List<NavigationViewItem> NavigationItems { get; set; }


    public MainWindowViewModel(IModuleCatalog moduleCatalog) //, IRegionManager regionManager
    {
        this.m_moduleCatalog = moduleCatalog;

        this.ThrowErrorCommand = new RelayCommand(this.ThrowError);
        this.SaleTicketCommand = new RelayCommand(this.SaleTicket);

        if (!_isInitialized)
        {
            InitializeViewModel();
        }
        //regionManager.RequestNavigate("mainRoot", "SayHello");
    }

    #region Command
    public RelayCommand ThrowErrorCommand { get; set; }
    public RelayCommand SaleTicketCommand { get; set; }
    #endregion

    #region 方法
    private void InitializeViewModel()
    {
        NavigationItems =
        [
            new NavigationViewItem()
            {
                Content = "Home",
                Icon = new SymbolIcon { Symbol = SymbolRegular.Home24 },
                TargetPageType =null //typeof(Views.Pages.DashboardPage),
            },
            new NavigationViewItem()
            {
                Content = "Data",
                Icon = new SymbolIcon { Symbol = SymbolRegular.DataHistogram24 },
                TargetPageType =null //typeof(Views.Pages.DataPage),
            },
        ];

        //NavigationFooter =
        //[
        //    new NavigationViewItem()
        //    {
        //        Content = "Settings",
        //        Icon = new SymbolIcon { Symbol = SymbolRegular.Settings24 },
        //        TargetPageType = typeof(Views.Pages.SettingsPage),
        //    },
        //];

        //TrayMenuItems = [new() { Header = "Home", Tag = "tray_home" }];

        _isInitialized = true;
    }
    private void ThrowError()
    {
        throw new Exception("错误");
    }

    private void SaleTicket()
    {
        if (!this.m_moduleCatalog.Contains("D7F3274A-2526-43FD-B278-099630BDA33E"))
        {
            System.Windows.MessageBox.Show("未注册");
        }
        else 
        {
            // 已注册，开菜单
            System.Windows.MessageBox.Show("已注册");
        }
    }

    #endregion
}
